#ifndef VECTOR_H
#define VECTOR_H
/**
 * @file vector.h
 * @author linxi (linxi177229@gmail.com)
 * @brief 主要是用于存储B-Tree的结点，private
 * 继承自std::vector，提供了一些可以用下标进行的search和remove，方便操作
 * @version 0.1
 * @date 2022-02-22
 *
 * @copyright Copyright (c) 2022
 *
 */
#include <vector>
using Rank = int;  //秩
/**
 * @brief 提供了一些提供了一些可以用下标进行的search和remove的vector，且不可继承
 *
 * @tparam T
 */
template <class T>
class Vector final : private std::vector<T> {
    typedef std::vector<T> vector;

   public:
    Vector() = default;
    Vector(const std::initializer_list<T>& list) : vector(list) {}
    explicit Vector(Rank n, const T& x = T{}) : vector(n, x) {}
    using vector::push_back;
    using vector::operator[];
    using vector::back;
    using vector::begin;
    using vector::emplace;
    using vector::emplace_back;
    using vector::empty;
    using vector::end;
    using vector::front;
    using vector::insert;
    using vector::pop_back;
    using vector::resize;
    using vector::size;
    Vector operator*(const Vector&) const;
    Vector operator+(const Vector&) const;
    Rank search(T const& e) const  //返回有序区间中最大的 <=e的下标
    {
        Rank searchPos = -1;
        // 找到 <= e的最大值的下标
        for (auto&& v : *this) {
            if (v > e) break;
            ++searchPos;
        }
        return searchPos;
    }
    template <class Args>
    Rank insert(Rank r, Args&& e)
    {
        return static_cast<Rank>(this->insert(this->begin() + r, std::forward<Args>(e)) -
                                 this->begin());
    }
    bool remove(Rank r)
    {
        if (r >= this->size()) return false;
        this->erase(this->begin() + r);
        return true;
    }
    Rank find(const T& e) const
    {
        Rank r = 0;
        for (auto&& v : *this) {
            if (v == e) return r;
            ++r;
        }
        return 0;
    }
};
#endif